from __future__ import absolute_import
from celery import shared_task
from .serverEvCfg import asynTaskExecution
import logging
logger = logging.getLogger('log')
from celery.contrib import rdb

@shared_task()
def ExecuteTestPlanAsynchronously(id):
    """
    异步执行任务，可以手动，也可以用来跑定时任务
    :param id:
    :return:
    """
    try:
        asynTaskExecution.ptTask().starPublicInter()  # 执行更新所有头部信息
        asynTaskExecution.ptTask().testBeingPlan(id=id)  # 执行中
        asynTaskExecution.ptTask().testExecutePlanAsynchronously(id=id)  # 去执行测试用例
        asynTaskExecution.ptTask().testOverPlan(id=id)  # 执行结束
        # logger.info("--------发送邮件---------------")
        # data1 = asynTaskExecution.ptTask().testSandEmail(id=id)
        # email(data=data1)
    except Exception as e:
        asynTaskExecution.ptTask().errorTestPlan(id=id)
        print("**运行错误完毕**")
        logger.error(e)
    return None


if __name__ == '__main__':
    ExecuteTestPlanAsynchronously.apply_async()
    pass